import { useTable, LIST_TYPE } from '@crud/index';
import { getSalesOrderList as getList } from '@/api/crm-kgj/sales';
import { formatParamsSelectVal } from '@/utils';

/** 线索类型 */
export const clueTypeOptions = [
  { label: '全部', value: -1 },
  { label: '过期会员', value: 1 },
  { label: '活跃新用户', value: 2 }
];
/** 订单类型 */
export const orderTypeOptions = [
  { label: '全部', value: -1 },
  { label: '线索续充', value: 1 },
  { label: '其它', value: 2 }
];
/** 优惠类型 */
export const discountsTypeOptions = [
  { label: '全部', value: -1 },
  { label: '价格折扣', value: 1 },
  { label: '赠送时长', value: 2 },
  { label: '无', value: 0 }
];
// const tradeStatusMap = toolOptions2Map(tradeStatusOptions);

export const useTableList = (options: any = {}) => {
  const columns = [
    {
      label: '流水单号',
      prop: 'order_no',
      align: 'center',
      showOverflowTooltip: true,
      type: 'copy',
      width: 250
    },
    {
      label: '用户名称',
      prop: 'user_name',
      width: 140,
      align: 'center'
    },
    {
      label: '手机号',
      prop: 'mobile',
      type: 'mobile',
      align: 'center',
      width: 180
    },
    {
      label: '购买类型',
      prop: 'product_title',
      align: 'center',
      width: 130
    },
    {
      label: '支付金额',
      prop: 'total_price',
      align: 'center',
      type: 'priceUnit',
      width: 100
    },
    {
      label: '优惠类型',
      prop: 'discount_type',
      align: 'center',
      minWidth: 170
    },
    {
      label: '支付时间',
      prop: 'order_time',
      type: 'dateTime',
      align: 'center',
      width: 177
    },
    {
      label: '订单类型',
      prop: 'order_type',
      align: 'center',
      width: 100
    },
    {
      label: '线索类型',
      prop: 'sales_user_type',
      align: 'center',
      width: 110
    },
    {
      label: '销售',
      prop: 'sales_name',
      minWidth: 100,
      align: 'center'
    }
  ];

  return useTable({
    ...options,
    type: LIST_TYPE.KGJ,
    params: {
      sales_order_type: 0,
      sales_id: '',
      discount_type: -1,
      order_type: -1,
      sales_user_type: -1
    },
    getParams: ({ _timeArr = [], ...params }) => {
      // 处理时间参数
      if (_timeArr?.length) {
        const [begin, end] = _timeArr;
        params.order_begin_time = begin;
        params.order_end_time = end;
      }
      return {
        ...params,
        ...formatParamsSelectVal([['channel', -1], ['sales_id', '']], params)
      };
    },
    columns,
    getList
  });
};
